package function.listen;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuItem;

import frame.closefileconfirm;
import frame.fileopen;
import frame.master;
import frame.data.contrldata;

public class menu1listen {
	private String info[]= {"新建(Ctrl+N)","打开(Ctrl+O)","保存(Ctrl+S)","另存为(Ctrl+Alt+S)","退出(Alt+F4)"};
	private JMenuItem[] item;
	public menu1listen() {
		item=new JMenuItem[info.length];
		contrldata.tool1=new JMenu("文件");
		for(int i=0;i<info.length;i++) {
			item[i]=new JMenuItem(info[i]);
			contrldata.tool1.add(item[i]);
		}
	}
	/**
	 * 加载子菜单监听
	 */
	public void loadmenuitemlisten(master ma) {
		item[0].addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				createnewfile(ma);
				master.m2l.updatecodeselectedformenuitem();
			}
		});
		item[1].addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				new fileopen(ma);
			}
		});
		item[3].addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				new closefileconfirm(
						master.fl.getfileinfoofnum(master.editfilenum),master.fl.getfileoldurlofnum(master.editfilenum),master.editfilenum,ma);
			}
		});
	}
	/**
	 * 新建文件
	 * @param ma
	 */
	public void createnewfile(master ma) {
		master.fl.createfile();
		master.editfilenum=master.fl.getfilenum()-1;
		contrldata.jt.setText("");
		contrldata.filetab.updateUI();
		master.t2l.updatelinenum(ma);
	}
}
